//
//  ClearViewController.m
//  SuperRadio
//
//  Created by Damon on 14/12/17.
//  Copyright (c) 2014年 三个臭皮匠. All rights reserved.
//

#import "ClearViewController.h"
#import "AboutUsCell.h"
#import "LoginViewController.h"
#import "SDImageCache.h"

@interface ClearViewController ()<UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate>

// 将tableView设置为属性
@property(nonatomic, retain) UITableView *aboutTableView;
@property(nonatomic, retain) UITableView *table;
@end

@implementation ClearViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"清除缓存";
    // Do any additional setup after loading the view.
    
    UIImageView *backImageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"];
    backImageView.image = [UIImage imageWithContentsOfFile:path];
    backImageView.alpha = 0.3;
    
    
    self.aboutTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.aboutTableView];
    self.aboutTableView.backgroundView = backImageView;
    // 关闭tableView的弹跳
    self.aboutTableView.bounces = NO;
    // 指定代理人
    self.aboutTableView.delegate = self;
    self.aboutTableView.dataSource = self;
    
    // 注册cell
    [self.aboutTableView registerClass:[AboutUsCell class] forCellReuseIdentifier:@"about"];
    [_aboutTableView release];
    
    
}

#pragma mark section的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

#pragma mark 设置cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    AboutUsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"about"];
    cell.backgroundColor = [UIColor clearColor];
    
        
    cell.nameLabel.text = @"清除图片缓存";
    // 定义一个float类型的变量 size , 表示可清理的图片所占空间大小
    float size = [[SDImageCache sharedImageCache] checkTmpSize];
    if (size == 0) {
        // 如果所占空间大小为0 不显示数字和图片
        cell.numLabel.text = nil;
        cell.rubbish.image = nil;
    } else {
        // 如果所占空间大小不为0 显示数字和图片
        cell.numLabel.text = [NSString stringWithFormat:@"%.2f", size];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"shanchu" ofType:@"png"];
        cell.rubbish.image = [UIImage imageWithContentsOfFile:path];
    }
    
   
    
    
    
    return cell;
}


#pragma mark 点击的cell的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.aboutTableView deselectRowAtIndexPath:indexPath animated:YES];
        
    // 清除图片缓存按钮的实现方法
    // 清理图片缓存
    //        NSLog(@"清理图片缓存");
    // 定义一个float类型的变量 size , 表示可清理的图片所占空间大小
    float size = [[SDImageCache sharedImageCache] checkTmpSize];
    // 调用方法, 清理图片内存
    [[SDImageCache sharedImageCache] clearDisk];
    NSString *str = [NSString stringWithFormat:@"缓存清除成功, 大小为%.2fMB", size];
    // 创建警告视图, 提示清理图片大小
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    // 调用show方法, 显示alertView
    [alertView show];
    // alertView的内存释放
    [alertView release];
    
    self.table = tableView;
    [tableView reloadData];
    
    
}





//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 100)];
//
//    self.aboutTableView.tableHeaderView =headerView;
//
////    AboutUsCell *headerCell = [tableView dequeueReusableCellWithIdentifier:@"about"];
////    [headerView addSubview:headerCell.nameLabel];
////    [headerView addSubview:headerCell.numLabel];
////    [headerView addSubview:headerCell.rubbish];
//
//
//    return headerView;
//}


- (void)dealloc
{
    [_aboutTableView release];
    [_table release];
    [super dealloc];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
